package com.xuelang.pipeline.entry.resource;

import com.xuelang.pipeline.app.resource.ClusterService;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.resource.IClusterService;
import com.xuelang.pipeline.client.resource.dto.ClusterDTO;
import com.xuelang.pipeline.client.resource.dto.ClusterQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 集群服务web控制类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Slf4j
@RestController
@RequestMapping("/cluster")
public class ClusterController implements IClusterService {

    @Autowired
    private ClusterService clusterService;

    @Override
    public ApiResult<PageRecord<ClusterDTO>> pageClusterList(PageParam<ClusterQuery> dtoPageParam) {
        return ApiResult.success(clusterService.pageList(dtoPageParam));
    }

    @Override
    public ApiResult<List<ClusterDTO>> conditionalClusterList(ClusterQuery clusterQuery) {
        return ApiResult.success(clusterService.list(clusterQuery));
    }

    @Override
    public ApiResult<Boolean> addCluster(ClusterDTO clusterDTO) {
        return ApiResult.success(clusterService.add(clusterDTO));
    }

    @Override
    public ApiResult<Boolean> updateCluster(ClusterDTO clusterDTO) {
        return ApiResult.success(clusterService.update(clusterDTO));
    }

    @Override
    public ApiResult<Boolean> deleteCluster(String clusterUuid) {
        return ApiResult.success(clusterService.delete(clusterUuid));
    }

    @Override
    public ApiResult<ClusterDTO> queryCluster(String clusterUuid) {
        return ApiResult.success(clusterService.query(clusterUuid));
    }

    @Override
    public ApiResult<Boolean> existsSpaceLimit(String clusterUuid) {
        return ApiResult.success(clusterService.existsSpaceByClusterUuid(clusterUuid));
    }
}